﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace VkClientIM.Logic
{
	public sealed class PlaylistViewModel
		: INotifyPropertyChanged

	{
		private ObservableCollection<AudioRecord> _items=new ObservableCollection<AudioRecord>();

		public PlaylistViewModel()
		{
			
		}

		public AudioRecord SelectedItem { get; set; }

		public ObservableCollection<AudioRecord> Items
		{
			get { return _items; }
		}

		public void AddAudioRecord(AudioRecord audioRecord)
		{
			audioRecord.PropertyChanged += OnAudioRecordPropertyChanged;
			_items.Add( audioRecord );
		}



		public void RemoveAudioRecord(AudioRecord audioRecord)
		{
			if (_items.Contains( audioRecord ))
			{
				audioRecord.PropertyChanged -= OnAudioRecordPropertyChanged;
				_items.Remove( audioRecord );
			}
		}

		private void OnAudioRecordPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			if (e.PropertyName == "IsSelected")
			{
				if (PropertyChanged != null)
				{
					PropertyChanged(this, new PropertyChangedEventArgs("SelectedItem"));
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
	}

	public sealed class AudioRecord
		: INotifyPropertyChanged
	{
		private bool _isPlaying;

		public Uri Url { get; set; }
		public string Artist { get; set; }
		public string Name { get; set; }
		public long Duration { get; set; }
		public bool IsSelected
		{
			get { return _isPlaying; }
			set
			{
				if (_isPlaying != value)
				{
					_isPlaying = value;
					PropertyChanged(this, new PropertyChangedEventArgs("IsSelected"));
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
	}
}
